package com.jqq.map_;

import java.util.*;

/**
 * @author 姬倩倩
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class MapFor {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("邓超", "孙俪");//替换book
        map.put("王宝强", "马蓉");
        map.put("宋喆", "马蓉");
        map.put(null, "刘亦菲");
        map.put("鹿晗", "关晓彤");

        //第一组keySet
        //先取出所有的key，通过key取出对应的value
        Set keyset = map.keySet();
        //1)增强for
        System.out.println("----第一种方式----");
        for (Object key : keyset) {
            System.out.println(key + "-" + map.get(key));
        }
        //2)迭代器
        System.out.println("----第二种方式----");
        Iterator iterator = keyset.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            System.out.println(key + "-" + map.get(key));
        }

        //第二组entrySet
        Set entryset = map.entrySet();
        System.out.println("----第一种方式----");
        for (Object o :entryset) {
//            System.out.println(o);
            Map.Entry m = (Map.Entry) o;
            System.out.println(m.getKey()+"-"+m.getValue());
        }
        System.out.println("----第二种方式----");
        Iterator iterator1 = entryset.iterator();
        while (iterator1.hasNext()) {
            Object o =  iterator1.next();
//            System.out.println(o);
            Map.Entry m = (Map.Entry) o;
            System.out.println(m.getKey()+"-"+m.getValue());
        }
        System.out.println("取出所有的value:");
        Collection values = map.values();
        System.out.println("========");
        for (Object o :values) {
            System.out.println(o);
        }
        System.out.println("========");
        Iterator iterator2 = values.iterator();
        while (iterator2.hasNext()) {
            Object o =  iterator2.next();
            System.out.println(o);
        }

    }
}
